package com.zzj.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zzj.bean.ShapeBean;
import com.zzj.dao.ProductDao;
import com.zzj.dao.ShapeDao;
import com.zzj.utils.Result;
import com.zzj.utils.StatusCode;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ShapeServiceImpl implements ShapeService {
    @Resource
    private ShapeDao shapeDao;
    @Resource
    private ProductDao productDao;

    @Override
    public PageInfo<ShapeBean> findAll(int pageNum,int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<ShapeBean> all = shapeDao.findAll();
        return new PageInfo<>(all);
    }

    @Override
    public Result updateShape(ShapeBean shapeBean) {
        shapeBean.setSstate("1");
        int i1 = shapeDao.updateShape(shapeBean);
        int i2 = productDao.updateProductState(shapeBean.getPid(), "1",shapeBean.getTid());
        if (i1 == 1 && i2 == 1){
            return new Result();
        }
        return new Result(false, StatusCode.ERROR,"操作失败");
    }
}
